import request from '@/utils/request'
import qs from 'qs'

// 报表分页查询
export function getReportPage(params) {
  return request({
    url: '/report/page',
    method: 'get',
    params,
  })
}

//恢复缺省
export function restoreReport(params) {
  return request({
    url: '/report/restore?reportName=' + params,
    method: 'put',
  })
}

// 删除一条数据
export function delReport(param) {
  return request({
    url: '/report/deleteByName?reportName=' + param,
    method: 'delete',
  })
}

// 新增模板
export function addTemplate(data) {
  return request({
    url: '/report/template',
    method: 'post',
    data,
  })
}

// 修改模板
export function updateTemplate(data) {
  return request({
    url: '/report/template',
    method: 'put',
    data,
  })
}

// 模板列表
export function pageList(params) {
  return request({
    url: '/report/template/page',
    method: 'get',
    params,
  })
}

// 重置模板
export function restoreTpl(id) {
  return request({
    url: '/report/template/restore/' + id,
    method: 'put',
  })
}

// 获取报表下拉框列表
export function loadReportProviders() {
  return request({
    url: '/report/list',
    method: 'get',
    headers: {
      isToken: false,
    },
  })
}

// 获取模板下拉框列表
export function getTemplateList() {
  return request({
    url: '/report/template/list',
    method: 'get',
  })
}

// 获取打印配置
export function getExportConfig(searchStr) {
  return request({
    url: '/ureport/config/report' + searchStr,
    method: 'get',
    headers: {
      isToken: false,
    },
  })
}

// 根据菜单code获取报表名称
export function getMenunameByCode(menuCode) {
  return request({
    url: '/menu/report/reportName/' + menuCode,
    method: 'get',
  })
}

// 根据打印code和使用部门获取报表名称
export function selectByCodeAndDept(params) {
  return request({
    url: '/report/template/selectByCodeAndDept',
    method: 'get',
    params,
  })
}

// 导出报表
export function exportReportByName(name) {
  return request({
    url: '/report/export/xml?reportName=' + name,
    method: 'get',
  })
}
export function doPrintData(data) {
  let query = ''
  if (data.query) {
    query = qs.stringify(data.query)
    delete data.query
  }
  return request({
    url: `/ureport/pdf/show?_u=${data._u}&token=${data.token}&${query}`,
    method: 'post',
    data,
    responseType: 'blob'
  })
}
